home *** CD-ROM | disk | FTP | other *** search
- /* difftime.c Turbo C Bible functions, p. 331 */
- #include <stdio.h>
- #include <time.h>
- main()
- {
- unsigned long i, count;
- double a, b, c, d, tused, tperstep;
- time_t tstart, tstop;
- printf("Enter number of times loop is run:");
- /* Ask user number of times "multiply" to be done */
- scanf(" %lu", &count);
- time(&tstart); /* Get current time by calling "time" */
- for (i=0; i < count; i++)
- {
- a = (double)(i-1);
- b = (double)(i+1);
- c = (double)(i*i);
- d = a * b - c;
- }
- time(&tstop); /* Get time again and print time used. */
- tused = difftime(tstop, tstart); /* in sec */
- tperstep = tused/(double)count;
- printf("Total time = %f seconds\n"
- "Time per iteration: %f milliseconds\n", tused,
- tperstep * 1000.0);
- }